<form id="<?php echo $uniqid;?>" method="post" style="padding: 8px;">
	<table border="0" width="100%" cellspacing="1" cellpadding="5" class="formtable datagrid-toolbar">
		<tr bgcolor="#FFFFFF">
			<td><span style="color: #cc3333">* </span>企业名称：<input type="text" style="width:200px;" v-model="company_name"
							class="forminput inputstyle validatebox-text textbox-prompt easyui-validatebox"
							placeholder="企业名称"></td>
		</tr>
		<tr bgcolor="#FFFFFF">
			<td><span style="color: #cc3333">* </span>企业法人：<input type="text" style="width:200px;" v-model="company_representative_name"
							class="forminput inputstyle validatebox-text textbox-prompt easyui-validatebox"
							placeholder="企业法人"></td>
		</tr>
		<tr bgcolor="#FFFFFF">
			<td><span style="color: #cc3333">* </span>企业联系电话：<input type="text" style="width:200px;" v-model="phone"
																  class="forminput inputstyle validatebox-text textbox-prompt easyui-validatebox"
																  placeholder="企业联系电话"></td>
		</tr>
		<tr bgcolor="#EFEFEF">
			<td>
				过滤条件：<input type="text" style="width:200px;" v-model="keywords"
					   class="forminput inputstyle validatebox-text textbox-prompt easyui-validatebox"
					   placeholder="地区名称">
				<a href="javascript:void(0);" @click="search();" class="l-btn l-btn-small "><span
						class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">过滤</span></span></a>
			</td>
		</tr>
		<tr bgcolor="#FFFFFF">
			<td>
				<ul id="selectqudaiareaMenu" name="menu_ids"></ul>
			</td>
		</tr>
	</table>
</form>

<script>
	var selectqudaiareaVm = new Vue({
		el: '#<?php echo $uniqid;?>',
		data: {
			treeData: JSON.parse('<?php echo json_encode($areas, JSON_UNESCAPED_UNICODE);?>'),
			keywords: '',
			company_name: '',
			company_representative_name: '',
			phone:''
		},
		mounted() {
			this.init();
		},
		methods: {
			init(){
				$('#selectqudaiareaMenu').tree({
					data: this.treeData,
					lines: true,
				}).tree('collapseAll');
			},
			search(){
				$.messager.progress();
				$.post('/admin/member/qudailevel', {keywords: selectqudaiareaVm.keywords}, (data)=> {
					$.messager.progress('close');
					if (data.ret === 0) {
						this.treeData = data.data;
						$('#selectqudaiareaMenu').tree({
							data: this.treeData,
							lines: true,
						}).tree('expandAll');
					} else {
						$.messager.alert('提示', data.msg, 'warning');
					}
				});
			},
		}
	});
	$('#qudailevelsubmit').click(function (data) {
		if(selectqudaiareaVm.company_name === ''){
			$.messager.alert('提示', '请输入企业名称！', 'warning');
			return;
		}
		if(selectqudaiareaVm.company_representative_name === ''){
			$.messager.alert('提示', '请输入企业法人！', 'warning');
			return;
		}
		if(selectqudaiareaVm.phone === '' || !/^(\d){2,}[0-9-]{4,}$/.test(selectqudaiareaVm.phone)){
			$.messager.alert('提示', '请输入企业联系电话，电话只能包含数字与-！', 'warning');
			return;
		}
		var row = $('#selectqudaiareaMenu').tree('getSelected');
		if (!row) {
			$.messager.alert('提示', '请先选择要代理商区域！', 'warning');
		}else{
			let area = {
				id: row.id,
				level: row.level,
				text: row.text,
				pid: row.pid,
			};
			$.messager.progress();
			$.post('/admin/member/setQudai', {id: '<?php echo $id;?>', area: area, phone:selectqudaiareaVm.phone, company_name:selectqudaiareaVm.company_name, company_representative_name:selectqudaiareaVm.company_representative_name}, function (data) {
				$.messager.progress('close');
				if (data.ret === 0) {
					$.messager.show({
						title: '提示',
						msg: data.msg,
						timeout: 3000,
						showType: 'slide'
					});
					membereditVm.params.qudai = data.data;
					$("#membereditdlg").dialog('close');
				} else {
					$.messager.alert('提示', data.msg, 'warning');
				}
			}, 'json');
		}
	});
</script>
